package com.hackerrank.challenges.trianglenumbers;

import java.util.Scanner;

public class Solution {
	private static void printOE(int n) {
		int c[] = new int[2 * n - 1];
		for(int i = 0; i < n; i++) {
			int nc[] = new int[2 * n - 1];
			nc[0] = 1;
			if(i > 0) {
				nc[1] = (c[0] + c[1]) % 2;
				for(int j = 2; j <= 2 * i - 2; j++)
					nc[j] = (c[j - 2] + c[j - 1] + c[j]) % 2;
				if(i > 1)
					nc[2 * i - 1] = (c[2 * i - 3] + c[2 * i - 2]) % 2;
				nc[2 * i] = c[2 * i - 2];
			}
			for(int j = 1; j < n - i; j++)
				System.out.print(" ");
			for(int j = 0; j < 2 * i + 1; j++) {
				if(nc[j] == 0)
					System.out.print("e");
				else
					System.out.print("o");
			}
			System.out.println();
			c = nc;
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		for(int t = 0; t < T; t++) {
			int N = in.nextInt();
			if(N < 3)
				System.out.println(-1);
			else if(N % 2 == 1)
				System.out.println(2);
			else if(N % 4 == 0)
				System.out.println(3);
			else
				System.out.println(4);
		}
	}
}
